<template>
  <div>
  <el-dialog
    title="批量操作设备类型选择"
    :visible.sync="showTypeList"
    width="555px"
    @close="close"
    style="border-bottom: 1px #eee solid;"
  >
    <ul class="dialogContent">
      <li class="dialogContentItem">
        <span class="el-dialog--center" center>设备类型:</span>
        <template>
          <el-select
          v-model="deviceTypes"
          placeholder="请选择设备类型"
          size="small"
          @focus="getDeviceType"
          >
            <el-option
            v-for="item in addDeviceTypeOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value"
            >
            </el-option>
          </el-select>
        </template>
      </li>
    </ul>
    <span slot="footer" class="dialog-footer" center>
        <el-button @click="close">取 消</el-button>
        <el-button
          type="primary"
          @click="batchDialog"
          :disabled="deviceTypes==''"
        >下一步</el-button
        >
      </span>
  </el-dialog>
  <batch-operat
    :showBatch="showBatch"
    :deviceTypes="deviceTypes"
    @batchOperatClose="batchOperatClose"
  ></batch-operat
  >
</div>
</template>

<script>
  import axios from 'axios'
  import batchOperat from './batchOperat'
  import qs from 'qs'

  export default {
    props: {
      showTypeList: {
        type: Boolean,
        default: false
      }
    },
    components: {
      batchOperat
    },
    data () {
      return {
        deviceTypes: '',
        addDeviceTypeOptions: [],

        showBatch: false
      }
    },
    methods: {
      close () {
        this.$emit("TypeListClose")
        this.deviceTypes = '',
        this.addDeviceTypeOptions = []
      },
      batchDialog  () {
        console.log(this.deviceTypes)
        this.showBatch = true
      },
      batchOperatClose () {
        this.showBatch = false
      },
      getDeviceType () {
        this.addDeviceTypeOptions = []
        this.pubilcFnAxios('types',{})
          .then(data =>{
          console.log(data)
          for (let i = 0;i < data.length;i++){
            this.addDeviceTypeOptions.push({label: data[i].name,value: data[i].id})
          }
        })
        .catch(() =>{
          console.log("请求失败！")
        })
      },
      pubilcFnAxios (urlString, params, method) {
        //公用axios数据请求
        return new Promise((resolve, reject) => {
          axios.get(this.api + urlString, {
            params: params,
            headers: {'X-Requested-With': 'XMLHttpRequest'},
            withCredentials: true,
          }).then(res => {
            resolve(res.data)
          }).catch(err => {
            reject('get请求错误')
          })
        })
      }
    }
  }
</script>

<style scoped>
  .selectBatchBox {
    display: inline-flex;
    flex-direction: row;
    width: 100%;
    justify-content: space-around;
  }

  .selectBatchBox .commonBox {
    width: 150px;
    height: 300px;
    border: 1px #eee solid;
    border-radius: 5px;
    margin-left: 10px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.12), 0 0 6px rgba(0, 0, 0, 0.04);
  }

  ::-webkit-scrollbar {
    width: 5px;
  }

  /* 滚动槽 */
  ::-webkit-scrollbar-track {
    -webkit-box-shadow: inset006pxrgba(0, 0, 0, 0.3);
    border-radius: 5px;
  }

  /* 滚动条滑块 */
  ::-webkit-scrollbar-thumb {
    border-radius: 5px;
    background: rgba(0, 0, 0, 0.2);
    /* -webkit-box-shadow:inset006pxrgba(0,0,0,0); */
  }

  ::-webkit-scrollbar-thumb:window-inactive {
    background: rgba(255, 0, 0, 0);
  }

  .selectBatchBox .commonBox .boxHead {
    display: inline-block;
    width: 100%;
    text-align: center;
    height: 25px;
    border-bottom: 1px solid #000;
    line-height: 25px;
    border-radius: 5px 5px 0 0;
    background: #eee;
  }

  .selectBatchBox .commonBox .boxContent {
    overflow-y: auto;
    overflow-x: hidden;
    width: 100%;
    height: 274px;
    position: relative;
  }

  .selectBatchBox .commonBox .boxContent .emptyText {
    display: inline-block;
    width: 100%;
    text-align: center;
    margin-top: 50%;
    transform: translateY(10px);
    color: #ddd;
  }

  .selectBatchBox .commonBox .boxContent .deviceList {
    height: 100%;
    width: 100%;
    padding: 0;
    margin: 0;
  }

  .selectBatchBox .commonBox .boxContent .deviceList .deviceListItem:hover {
    background: #e4e7ed;
  }

  .selectBatchBox .commonBox .boxContent .deviceList .deviceListItem {
    background-color: #ecf5ff;
    border-color: rgba(0, 0, 0, 0.04);
    display: inline-block;
    height: 32px;
    padding: 0 10px;
    line-height: 30px;
    font-size: 12px;
    color: #409eff;
    border-width: 1px;
    border-style: solid;
    border-radius: 4px;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    white-space: nowrap;
    width: 100%;
    margin: 2px 0 0 0;
  }

  .selectBatchBox
  .commonBox
  .boxContent
  .deviceList
  .deviceListItem
  .deviceListItem_del {
    display: inline-block;
    float: right;
  }

  .selectBatchBox
  .commonBox
  .boxContent
  .deviceList
  .deviceListItem
  .deviceListItem_text {
    display: inline-block;
    padding: 0 0 0 5px;
  }

  .selectBatchBox
  .commonBox
  .boxContent
  .deviceList
  .deviceListItem
  .deviceListItem_del
  .del-tag {
    cursor: pointer;
  }

  .selectBatchBox
  .commonBox
  .boxContent
  .deviceList
  .deviceListItem
  .deviceListItem_del
  .del-tag:hover {
    color: red;
  }

  .tabBoxContent {
    text-align: center;
    padding: 10px 0 0 0;
    width: 100%;
    height: 157px;
    overflow: hidden;
    /* background: #eee; */
    display: inline-block;
    /* overflow: hidden; */
    position: relative;
  }

  .tabBoxContent .selectItemBox {
    margin-top: 60px;
    height: 100%;
    width: 100%;
  }

  .tabBoxContent .headText {
  }

  .tabBoxContent .timerItem {
  }

  .tabBoxContent .selectItemTimer {
    margin: 5px 0 5px 0;
  }

  .tabBoxContent .checkTimer {
    margin-top: 15px;
    color: #409eff;
    cursor: pointer;
  }

</style>
